package com.itheima.controller;

import com.itheima.dto.RoleMenuDto;
import com.itheima.dto.UserDto;
import com.itheima.entry.PageResult;
import com.itheima.entry.QueryPageBean;
import com.itheima.entry.Result;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-11-23 9:44
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Reference
    private UserService userService;
    @PostMapping("/queryAllByPage")
    public PageResult queryAllByPage(@RequestBody QueryPageBean queryPageBean){
       return userService.queryAllByPage(queryPageBean);
    }
    @PostMapping("/save")
    public void save(@RequestBody User user){
        userService.saveOrUpdate(user);
    }
    @GetMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") Long id){
        userService.deleteById(id);
    }
    @PostMapping("/reset")
    public void reset(@RequestBody User user){
        userService.updateByUserName(user);
    }
    @GetMapping("/findAllUser")
    public List<User> findAllUser(){
       return userService.findAllUser();
    }
    @GetMapping("/findRoleByUserId/{id}")
    public Long[] findRoleByUserId(@PathVariable("id") Long id){
        return userService.findRoleByRoleId(id);
    }
    @PostMapping("/addRole")
    public Result addMenu(@RequestBody UserDto userDto){
        System.out.println("userDto = " + userDto);
        boolean flag= userService.addRole(userDto);
        return new Result(flag);
    }
}
